﻿#region

using MediaSage.Lib.Utilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#endregion

namespace MediaSageLibTest
{
    [TestClass]
    public class RegistryHelperTests
    {
        #region Methods

        /// <summary>
        ///     Method has to be run with admin priviledges
        /// </summary>
        [TestMethod]
        public void CreateNewKey()
        {
            Assert.AreEqual(true, RegistryHelper.WriteKey(@"SOFTWARE\MediaSage", null, true), "Failed to create key");
        }

        /// <summary>
        ///     Method has to be run with admin priviledges
        /// </summary>
        [TestMethod]
        public void DeleteKey()
        {
            Assert.AreEqual(true, RegistryHelper.WriteKey(@"SOFTWARE\MediaSage", null, true), "Failed to create key");
            Assert.AreEqual(true, RegistryHelper.DeleteKey(@"SOFTWARE\MediaSage"), "Failed to delete key");
            Assert.AreEqual(false, RegistryHelper.KeyExists(@"SOFTWARE\MediaSage"), "Key still exists");
        }

        [TestMethod]
        public void SetGetValue()
        {
            Assert.AreEqual(true, RegistryHelper.WriteKey(@"SOFTWARE\MediaSage\RegistryTest", null, true),
                            "Failed to create key");
            Assert.AreEqual(true, RegistryHelper.SetKeyValue(@"SOFTWARE\MediaSage\RegistryTest", "Test", 1));
            Assert.AreEqual(1, (int) RegistryHelper.GetKeyValue(@"SOFTWARE\MediaSage\RegistryTest", "Test"));
        }

        [TestMethod]
        public void TestGetValues()
        {
            // Key may not exist if this is the first test, so we dont care if it is true or false, just that its gone
            RegistryHelper.DeleteKey(@"SOFTWARE\MediaSage\RegistryTest");
            Assert.AreEqual(true, RegistryHelper.WriteKey(@"SOFTWARE\MediaSage\RegistryTest", null, true),
                            "Failed to create key");
            Assert.AreEqual(true, RegistryHelper.SetKeyValue(@"SOFTWARE\MediaSage\RegistryTest", "Test1", 1));
            Assert.AreEqual(true, RegistryHelper.SetKeyValue(@"SOFTWARE\MediaSage\RegistryTest", "Test2", 2));
            Assert.AreEqual(true, RegistryHelper.SetKeyValue(@"SOFTWARE\MediaSage\RegistryTest", "Test3", 3));
            Assert.AreEqual(true, RegistryHelper.SetKeyValue(@"SOFTWARE\MediaSage\RegistryTest", "Test4", 4));
            Assert.AreEqual(4, RegistryHelper.GetKeyValues(@"SOFTWARE\MediaSage\RegistryTest").Count);
        }

        #endregion Methods
    }
}